var app = getApp()
var imageUtil = require('../../utils/util.js');
Page({
  // onLoad: function () {
  // },
  // imageLoad: function (e) {
  //   var imageSize = imageUtil.imageUtil(e)
  //   this.setData({
  //     swiperHeight: imageSize.imageWidth,
  //     imagewidth: imageSize.imageWidth,
  //     imageheight: imageSize.imageHeight,
  //   })
  // },
  data: {
    indicatorDots: true, //是否显示面板指示点
    autoplay: true, //是否自动切换
    interval: 5000, //自动切换时间间隔,5s
    duration: 1000, //  滑动动画时长1s
    circular: true,
    imgheights: [],
    current: 0,
    imgwidth: 750,


    // banner  商品轮播图
    imgUrls: [
      "https://res.lancome.com.cn/resources/2020/9/17/1600351443338258_900X900.jpg?version=20200917220352530",
      "https://res.lancome.com.cn/resources/2020/9/17/16003514506527123_920X920.jpg?version=20200917220352530",
      "https://res.lancome.com.cn/resources/2020/9/11/15998112890781924_920X920.jpg?version=20200917220352530",
      "https://res.lancome.com.cn/resources/2020/9/11/15998112853224645_920X920.jpg?version=20200917220352530",
      "https://res.lancome.com.cn/resources/2020/7/1/15935898796953944_920X920.jpg?version=20200917220352530"
    ],

    // 商品详情介绍
    detailImg: [
      "https://img.alicdn.com/imgextra/i1/2360209412/O1CN01GGeZZd2JOkOJJzLQr_!!2360209412.jpg",
      "https://img.alicdn.com/imgextra/i3/2360209412/O1CN01hihLhJ2JOkOMxUEmC_!!2360209412.jpg",
      "https://img.alicdn.com/imgextra/i4/2360209412/O1CN01ErwAsJ2JOkOKYF5gV_!!2360209412.jpg",
      "https://img.alicdn.com/imgextra/i3/2360209412/O1CN01sTAdeI2JOkOGHqSKg_!!2360209412.jpg",
      "https://gdp.alicdn.com/imgextra/i2/2360209412/O1CN01Oi4HCY2JOkL954Scr_!!2360209412.jpg",
      "https://gdp.alicdn.com/imgextra/i2/2360209412/O1CN01TiYmCY2JOkMfemeGg_!!2360209412.jpg",
    ],
  },
  //banner 轮播图
  imageLoad: function (e) {
    //获取图片真实宽度
    var imgwidth = e.detail.width,
      imgheight = e.detail.height,
      //宽高比
      ratio = imgwidth / imgheight;
    //计算的高度值
    var viewHeight = 750 / ratio;
    var imgheight = viewHeight
    var imgheights = this.data.imgheights
    //把每一张图片的高度记录到数组里
    imgheights[e.target.dataset['index']] = imgheight; // 改了这里 赋值给当前 index
    this.setData({
      imgheights: imgheights,
    })
  },
  //banner swiper
  bindchange: function (e) {
    this.setData({
      current: e.detail.current
    })
  },
  //预览图片
  previewImage: function (e) {
    var current = e.target.dataset.src;

    wx.previewImage({
      current: current, // 当前显示图片的http链接  
      urls: this.data.imgUrls // 需要预览的图片http链接列表  
    })
  },
  // 收藏
  addLike() {
    this.setData({
      isLike: !this.data.isLike
    });
  },
  // 跳到购物车
  toCar() {
    wx.switchTab({
      url: '/pages/cart/cart'
    })
  },
  // 立即购买
  immeBuy() {
    wx.showToast({
      title: '购买成功',
      icon: 'success',
      duration: 2000
    });
  },
})